/*
 * claplan_optimization.cc
 *
 *  Created on: 3 Nov 2013
 *      Author: Tom Vercauteren
 */

#include "claplan_optimization.h"

#include "claplan_print.h"

using std::string;
using std::endl;

ClaplanOptimization::ClaplanOptimization(const ClaplanOptimization &co)
{
	if (this != &co) *this = co;
}

ClaplanOptimization& ClaplanOptimization::operator=(const ClaplanOptimization &co)
{
	if (this != &co)
	{
		mask = co.mask;
		routine = co.routine;
		max_time = co.max_time;
		tol = co.tol;
		rtol = co.rtol;
		mirw = co.mirw;
		nskew = co.nskew;
		disp_quant = co.disp_quant;
	}
	return *this;
}

unsigned long ClaplanOptimization::getDispQuant() const
{
	return disp_quant;
}

void ClaplanOptimization::setDispQuant(unsigned long dispQuant)
{
	disp_quant = dispQuant;
	mask.disp_quant = 1;
}

void ClaplanOptimization::unsetDispQuant()
{
	disp_quant = 0;
	mask.disp_quant = 0;
}

unsigned char ClaplanOptimization::isDispQuantSet() const
{
	return mask.disp_quant;
}

double ClaplanOptimization::getMaxTime() const
{
	return max_time;
}

void ClaplanOptimization::setMaxTime(double maxTime)
{
	max_time = maxTime;
	mask.max_time = 1;
}

void ClaplanOptimization::unsetMaxTime()
{
	max_time = 0;
	mask.max_time = 0;
}
unsigned char ClaplanOptimization::isMaxTimSet() const
{
	return mask.max_time;
}

unsigned long ClaplanOptimization::getMirw() const
{
	return mirw;
}

void ClaplanOptimization::setMirw(unsigned long mirw)
{
	this->mirw = mirw;
	mask.mirw = 1;
}

void ClaplanOptimization::unsetMirw()
{
	mirw = 0;
	mask.mirw = 0;
}
unsigned char ClaplanOptimization::isMirwSet() const
{
	return mask.mirw;
}

unsigned long ClaplanOptimization::getNskew() const
{
	return nskew;
}

void ClaplanOptimization::setNskew(unsigned long nskew)
{
	this->nskew = nskew;
	mask.nskew = 1;
}

void ClaplanOptimization::unsetNskew()
{
	nskew = 0;
	mask.nskew = 0;
}

unsigned char ClaplanOptimization::isNskewSet() const
{
	return mask.nskew;
}

const std::string& ClaplanOptimization::getRoutine() const
{
	return routine;
}

void ClaplanOptimization::setRoutine(const std::string& routine)
{
	this->routine = routine;
	mask.routine = 1;
}

void ClaplanOptimization::unsetRoutine()
{
	this->routine = "";
	mask.routine = 0;
}

unsigned char ClaplanOptimization::isRoutineSet() const
{
	return mask.routine;
}

double ClaplanOptimization::getRtol() const
{
	return rtol;
}

void ClaplanOptimization::setRtol(double rtol)
{
	this->rtol = rtol;
	mask.rtol = 1;
}

void ClaplanOptimization::unsetRtol()
{
	this->rtol = 0;
	mask.rtol = 0;
}

unsigned char ClaplanOptimization::isRtolSet() const
{
	return mask.rtol;
}

double ClaplanOptimization::getTol() const
{
	return tol;
}

void ClaplanOptimization::setTol(double tol)
{
	this->tol = tol;
	mask.tol = 1;
}

void ClaplanOptimization::unsetTol()
{
	this->tol = 0;
	mask.tol = 0;
}

unsigned char ClaplanOptimization::isTolSet() const
{
	return mask.tol;
}

std::ostream & operator<<(std::ostream & os, const ClaplanOptimization &co)
{
	os << "optimization :" << endl;
	if (co.isRoutineSet() & 1)
		print_kv<string, string>(os, "routine", co.routine);
	if (co.isMaxTimSet() & 1)
		print_kv<string, double>(os, "max_time", co.max_time);
	if (co.isTolSet() & 1) print_kv<string, double>(os, "tol", co.tol);
	if (co.isRtolSet() & 1) print_kv<string, double>(os, "rtol", co.rtol);
	if (co.isMirwSet() & 1)
		print_kv<string, unsigned long>(os, "mirw", co.mirw);
	if (co.isNskewSet() & 1)
		print_kv<string, unsigned long>(os, "nskew", co.nskew);
	if (co.isDispQuantSet() & 1)
		print_kv<string, unsigned long>(os, "disp_quant", co.disp_quant);
	return os << endl;
}

